<div class="componentheading"><?php echo $page_title;?></div>
<div><?php global_message(); ?></div>
<?php
	$isEdit = isset($_user) ? true : false;
	$text = empty($isEdit) ? 'Add' : 'Update';
	$selected = 'selected = "selected"';
?>
<form method="post" id="newForm">
<div class="box-header">New User</div>
<div class="box table">
<table width="100%">
    <tr>
        <td width="25%"><strong>First Name</strong></td>
        <td width="75%"><input type="text" class="required" name="first_name" id="first_name" value="<?php if($isEdit) echo $_user->first_name;?>" /></td>
    </tr>
    <tr>
    	<td><strong>Last Name</strong></td>
        <td><input type="text" class="required" name="last_name" id="last_name" value="<?php if($isEdit) echo $_user->last_name;?>" /></td>
    </tr>
    <tr>
    	<td><strong>Username</strong></td>
        <td><input type="text" class="required" name="username" id="username" value="<?php if($isEdit) echo $_user->username;?>" /></td>
    </tr>
    <tr>
    	<td><strong>Password</strong></td>
        <td><input type="password" class="<?php if(!$isEdit) echo 'required';?>" name="password" id="password" value="" /></td>
    </tr>
    <tr>
    	<td><strong>Confirm Password</strong></td>
        <td><input type="password" class="" name="re_password" id="re_password" value="" /></td>
    </tr>
    <tr>
    	<td><strong>Email</strong></td>
        <td><input type="text" class="required email" name="email" id="email" value="<?php if($isEdit) echo $_user->email;?>" /></td>
    </tr>
    <tr>
    	<td><strong>Status</strong></td>
        <td>
            <select name="status" id="status">
                <option value="active" <?php if($isEdit){ if($_user->status == 'active') echo $selected;}?>>Active</option>
                <option value="inactive" <?php if($isEdit){ if($_user->status == 'inactive') echo $selected;}?>>Inactive</option>
            </select>
        </td>
    </tr>
    <tr>
    	<td>&nbsp;</td>
        <td>
            <input type="submit" name="submit_user" id="submit_user" value="<?php echo $text;?>">
            <input type="button" onclick="window.location.href = '<?php echo site_url('users');?>'" value="Back" />
        </td>
    </tr>
</table>
</div>
</form>
<script>
$(document).ready(function(){
	//initialize jquery validation
	$('#newForm').validate({
		rules: {
            password: {
                minlength: 6
            },
            re_password: {
                equalTo: "#password"
            }

        },
        messages: {
            password: {
                required : "Please enter your password",
                minlength: "Please enter password of more than 6 characters"
            },
            re_password: {
                equalTo: "Your Password does not match"
            }
        }					   
	});
								
});

</script>
